package com.laowang.project.system.service.impl;

import java.util.List;

import com.laowang.common.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.MyCyhPromoVipMapper;
import com.laowang.project.system.domain.MyCyhPromoVip;
import com.laowang.project.system.service.MyCyhPromoVipService;

/**
 * 推广大使推会员配置Service业务层处理
 *
 * @author laowang
 * @date 2024-01-15
 */
@Service
public class MyCyhPromoVipServiceImpl implements MyCyhPromoVipService {
    @Autowired
    private MyCyhPromoVipMapper myCyhPromoVipMapper;

    /**
     * 查询推广大使推会员配置
     *
     * @param id 推广大使推会员配置ID
     * @return 推广大使推会员配置
     */
    @Override
    public MyCyhPromoVip selectMyCyhPromoVipById(Integer id) {
        return myCyhPromoVipMapper.selectMyCyhPromoVipById(id);
    }

    /**
     * 查询推广大使推会员配置列表
     *
     * @param myCyhPromoVip 推广大使推会员配置
     * @return 推广大使推会员配置
     */
    @Override
    public List<MyCyhPromoVip> selectMyCyhPromoVipList(MyCyhPromoVip myCyhPromoVip) {
        return myCyhPromoVipMapper.selectMyCyhPromoVipList(myCyhPromoVip);
    }

    /**
     * 新增推广大使推会员配置
     *
     * @param myCyhPromoVip 推广大使推会员配置
     * @return 结果
     */
    @Override
    public int insertMyCyhPromoVip(MyCyhPromoVip myCyhPromoVip) {
        Integer promoteId = myCyhPromoVip.getPromoteId();
        if (promoteId == null){
            throw new CustomException("推广大使不能为空");
        }
        Integer vipLevel = myCyhPromoVip.getVipLevel();
        if (vipLevel == null){
            throw new CustomException("会员级别不能为空");
        }
        MyCyhPromoVip myCyhPromoVip1 =   myCyhPromoVipMapper.selectByPromoteIdAndVipLevel(promoteId,vipLevel);
        if (myCyhPromoVip1 !=null){
            throw new CustomException("该推广大使与会员信息已存在");
        }


        return myCyhPromoVipMapper.insertMyCyhPromoVip(myCyhPromoVip);
    }

    /**
     * 修改推广大使推会员配置
     *
     * @param myCyhPromoVip 推广大使推会员配置
     * @return 结果
     */
    @Override
    public int updateMyCyhPromoVip(MyCyhPromoVip myCyhPromoVip) {

        Integer promoteId = myCyhPromoVip.getPromoteId();
        if (promoteId == null){
            throw new CustomException("推广大使不能为空");
        }
        Integer vipLevel = myCyhPromoVip.getVipLevel();
        if (vipLevel == null){
            throw new CustomException("会员级别不能为空");
        }
        MyCyhPromoVip myCyhPromoVip1 =   myCyhPromoVipMapper.selectByPromoteIdAndVipLevel(promoteId,vipLevel);
        if (myCyhPromoVip1 !=null){
            if (!myCyhPromoVip1.getId().equals(myCyhPromoVip.getId())){
                throw new CustomException("该推广大使与会员信息已存在");
            }
        }

        return myCyhPromoVipMapper.updateMyCyhPromoVip(myCyhPromoVip);
    }

    /**
     * 批量删除推广大使推会员配置
     *
     * @param ids 需要删除的推广大使推会员配置ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhPromoVipByIds(Integer[] ids) {
        return myCyhPromoVipMapper.deleteMyCyhPromoVipByIds(ids);
    }

    /**
     * 删除推广大使推会员配置信息
     *
     * @param id 推广大使推会员配置ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhPromoVipById(Integer id) {
        return myCyhPromoVipMapper.deleteMyCyhPromoVipById(id);
    }
}
